using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class EE_UI_Main : MonoBehaviour
{
    [SerializeField] public GameObject elements = null;
    [SerializeField] public TextMeshProUGUI goldText = null;
    [SerializeField] public TextMeshProUGUI elixerText = null;
    [SerializeField] public TextMeshProUGUI gemsText = null;
    [SerializeField] private Button shopButton = null;

    [SerializeField] public EE_BuildGrid_Controller grid = null;
    [SerializeField] public EE_Building_Controller[] buildingPrefabs = null;
    
    [Header("Buttons")] 
    public Transform buttonsParent = null;
    public EE_UI_Button buttonCollectGold = null;
    public EE_UI_Bar buildBar = null;
    private static EE_UI_Main instance = null; public static EE_UI_Main Instance {get{return instance;}}
    private bool active = true; public bool isActive {get{return active;}}

    private void Awake()
    {
        instance = this;
        elements.SetActive(true);
    }

    private void Start()
    {
        shopButton.onClick.AddListener(ShopButtonClicked);
    }

    private void ShopButtonClicked()
    {
        if (EE_Building_Controller.Instance != null && !EE_Building_Controller.Instance.IsConfirmed)
        {
            // 如果没有被确认建造, 那么进入商店时销毁该建筑
            EE_UI_Build.Instance.Cancel();
        }
        EE_UI_Shop.Instance.SetStatus(true);
        SetStatus(false);
    }

    public void SetStatus(bool status)
    {
        active = status;
        elements.SetActive(status);
    }

    public EE_Building_Controller GetBuildingPrefab(EE_Data.BuildingID id)
    {
        for (int i = 0; i < buildingPrefabs.Length; i++)
        {
            if (buildingPrefabs[i].id == id)
            {
                return buildingPrefabs[i];
            }
        }
        return null;
    }
}